﻿@model DeliveryManage.Model.Sys_Role
@{
    Layout = null;
    Dictionary<string, string> actiondic = ViewBag.ActionList as Dictionary<string, string>;
    DeliveryManage.Models.ReturnMsgModel returnMsg = ViewBag.ReturnMsgModel;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>编辑角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="~/Content/font.css">
    <link rel="stylesheet" href="~/Content/framemain.css">
    <link rel="stylesheet" href="~/Content/roletree.css" />
    <link href="~/Content/icon/iconfont.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <script type="text/javascript" src="~/Scripts/laymain.js"></script>

    <style type="text/css">
        .tree-list .col-1 {
            padding-left: 1%;
            width: 30%;
        }

        .tree-list .col-2 {
            width: 60%;
        }

        .tree-list .col-2-3 {
            width: 60%;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            //操作提示
            if (@returnMsg.code == 400) {
                layer.msg('@returnMsg.msg', { icon: 5, title: '提示' }, function (index) {
                  layer.close();
                })
            }
            //初始化分类的结构
            initCategoryHtml('.tree-list', 1);
            //初始化分类的事件
            $('.tree-list').initCategoryTree(true);
            //是否启用权限
            //if ($("#role_type").find("option:selected").attr("value") == "") {
            //    $(".tree-list").find("input[type='checkbox']").prop("disabled", true);
            //}
            $("#role_type").change(function () {
                if ($(this).find("option:selected").attr("value") == 1) {
                    $(".tree-list").find("input[type='checkbox']").prop("checked", false);
                    $(".tree-list").find("input[type='checkbox']").prop("disabled", true);
                } else {
                    $(".tree-list").find("input[type='checkbox']").prop("disabled", false);
                }
            });
        });
        $(document).ready(function () {
            $("#myform").submit(function () {
                var data = $(this).serialize();
                layer.confirm('确认提交吗?', { icon: 3, title: '提示' }, function (index) {
                    $.ajax({
                        type: "POST",
                        url: "/System/RoleEdit",
                        data: data,
                        success: function (obj) {
                            if (obj.status == true) {
                                layer.msg(obj.msg, { icon: 6, title: '提示' }, function (index) {
                                    window.parent.window.location.href = '/System/RoleManage';
                                });
                            } else {
                                layer.msg(obj.msg, { icon: 5, title: '提示' }, function (index) {
                                    layer.close();
                                    location.reload();
                                });
                            }
                        }
                    })
                    layer.close();
                });
                return false;

            })

        })
    </script>
</head>
<body>
    <form id="myform">
        @{
            if (returnMsg.code == 200)
            {
                @Html.HiddenFor(m => m.id)
                @Html.HiddenFor(m => m.is_sys)
                @Html.Hidden("AddOrEdit", (string)ViewBag.AddOrEdit)
                <div class="layui-fluid layui-form">
                    <div class="layui-row">
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>角色类型
                            </label>
                            <div class="layui-input-inline">
                                @Html.DropDownListFor(m => m.role_type, ViewData["roletype"] as SelectList, new { @class = "layui-input" })
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>角色名称
                            </label>
                            <div class="layui-input-inline">
                                @Html.TextBoxFor(m => m.role_name, new { @autocomplete = "off", @class = "layui-input", @placeholder = "请输入角色名称" })
                                @*<input type="text" name="rolename" id="rolename" lay-verify="required" autocomplete="off" class="layui-input" value="" />*@
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*请输入角色名称</span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label for="L_email" class="layui-form-label">
                                <span class="x-red">*</span>管理权限
                            </label>
                            <div class="layui-input-inline">
                                <div class="tree-list">
                                    <div class="thead">
                                        <div class="col col-1">导航名称</div>
                                        <div class="col col-2">权限分配</div>
                                    </div>
                                    <ul>
                                        @foreach (DeliveryManage.Model.Sys_Navigation item in ViewBag.NavList)
                                        {
                                            string[] actionarr = item.action_type.Split(',');
                                            <li class="layer-@item.class_layer">
                                                <div class="tbody">
                                                    <div class="col index col-1">
                                                        @*<asp:HiddenField ID="hidName" name="hidName" Value='@item.name >' runat="server" />
                                                        <asp:HiddenField ID="hidActionType" name="hidActionType" Value='@item.action_type' runat="server" />*@
                                                        @item.title
                                                    </div>
                                                    <div class="layui-form col col-2-3">
                                                        @foreach (string key in actionarr)//actiondic.Keys
                                                        {
                                                            DeliveryManage.Model.Sys_RoleValue modelt = null;
                                                            if (Model.user_role_values != null)
                                                            { modelt = Model.user_role_values.Find(p => p.nav_name == item.name && p.action_type.Contains(key)); }
                                                            if (modelt != null)
                                                            {
                                                                <input type="checkbox" name="cblActionType" value="@item.name + @key" id="@key+@item.id" lay-skin="primary" class="cbllist checkall" checked="checked" title="@actiondic[key]"/>
                                                                <label for="@key+@item.id"></label>
                                                            }
                                                            else
                                                            {
                                                                <input type="checkbox" name="cblActionType" value="@item.name + @key" id="@key+@item.id"  lay-skin="primary" class="cbllist checkall"  title="@actiondic[key]" />
                                                                <label for="@key+@item.id"></label>
                                                            }
                                                        }
                                                    </div>
                                                </div>
                                            </li>
                                        }
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                            </label>
                            <input id="btnSubmit" name="btnSubmit" type="submit" value="保存信息" class="layui-btn" />
                        </div>
                    </div>
                </div>
            }
        }
        <script>
            layui.use(['form', 'layer'],
                function () {
                    $ = layui.jquery;
                    var form = layui.form,
                        layer = layui.layer;
                });
        </script>
    </form>
</body>
</html>
